package org.simpleframework.singleton;
public class LazyDoubleCheckSingleton {
    private volatile static LazyDoubleCheckSingleton instance = null;
    private LazyDoubleCheckSingleton(){}

    /**
     *  双重检查机制
     *  多线程时，通过加锁保证只有一个线程能够创建对象
     *  同时改变了锁的粒度，在获取实例时不需要加锁了
     * @return
     */
    public static LazyDoubleCheckSingleton getInstance(){
        if(instance == null){
            synchronized (LazyDoubleCheckSingleton.class){
                if(instance == null){
                    instance = new LazyDoubleCheckSingleton();
                }
            }
        }
        return instance;
    }
}
